home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / corel.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  12.7 KB  |  406 lines

  1. /*
  2.  * $Id: corel.trm,v 1.7 1995/12/20 21:47:42 drd Exp $
  3.  */
  4.  
  5. /*
  6.    corel.trm
  7.  
  8.    A modified ai.trm for CorelDraw import filters
  9.    by Chris Parks, parks@physics.purdue.edu
  10.    Import from CorelDraw with the CorelTrace filter
  11.  
  12.    syntax: set terminal default
  13.            set terminal mode "fontname" fontsize,xsize,ysize,linewidth
  14.  
  15.            mode= color or monochrome             (default=mono)
  16.            "fontname"= postscript font name      (default="SwitzerlandLight")
  17.            fontsize  = size of font in points    (default=22pt)
  18.            xsize     = width of page in inches   (default=8.2in)
  19.            ysize     = height of page in inches  (default=10in)
  20.            linewidth = width of lines in points  (default=1.2pt)
  21.  
  22. */
  23.  
  24. /* 
  25.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  26.  */
  27.  
  28. #ifndef GOT_DRIVER_H
  29. #include "driver.h"
  30. #endif
  31.  
  32. #ifdef TERM_REGISTER
  33. register_term(corel)
  34. #endif
  35.  
  36. #ifdef TERM_PROTO
  37. TERM_PUBLIC void COREL_options __P((void));
  38. TERM_PUBLIC void COREL_init __P((void));
  39. TERM_PUBLIC void COREL_graphics __P((void));
  40. TERM_PUBLIC void COREL_text __P((void));
  41. TERM_PUBLIC void COREL_reset __P((void));
  42. TERM_PUBLIC void COREL_linetype __P((int linetype));
  43. TERM_PUBLIC void COREL_move __P((unsigned int x, unsigned int y));
  44. TERM_PUBLIC void COREL_vector __P((unsigned int x, unsigned int y));
  45. TERM_PUBLIC void COREL_put_text __P((unsigned int x, unsigned int y, char *str));
  46. TERM_PUBLIC int COREL_text_angle __P((int ang));
  47. TERM_PUBLIC int COREL_justify_text __P((enum JUSTIFY mode));
  48. #define CORELD_XMAX  5960            /* 8.2 inches wide */
  49. #define CORELD_YMAX  7200            /* 10 inches high  */
  50. #define CORELD_VTIC  (CORELD_YMAX/80)
  51. #define CORELD_HTIC  (CORELD_YMAX/80)
  52. #define CORELD_VCHAR (22*COREL_SC)      /* default is 22 point characters */
  53. #define CORELD_HCHAR (22*COREL_SC*6/10)
  54. #endif
  55.  
  56. #ifndef TERM_PROTO_ONLY
  57. #ifdef TERM_BODY
  58.  
  59. /* plots for publication should be sans-serif (don't use TimesRoman) */
  60. char corel_font[MAX_ID_LEN+1] = "SwitzerlandLight" ; /* name of font */
  61. int corel_fontsize = 22;                            /* size of font in pts */
  62. TBOOLEAN corel_color = FALSE;
  63. TBOOLEAN corel_stroke = FALSE;
  64. int corel_path_count=0;            /* count of lines in path */
  65. int corel_ang=0;                   /* text angle */
  66. enum JUSTIFY corel_justify=LEFT;   /* text is flush left */
  67.  
  68.  
  69. /* default mode constants */
  70. #define CORELD_XOFF  0               /* page offset in pts */
  71. #define CORELD_YOFF  0
  72. #define COREL_SC     (10.0)           /* scale is 1pt = 10 units */
  73. #define CORELD_LW    (1.2*COREL_SC)  /* linewidth = 1.2 pts */
  74.  
  75. unsigned int corel_xmax=CORELD_XMAX;
  76. unsigned int corel_ymax=CORELD_YMAX;
  77. float corel_lw=CORELD_LW;
  78.  
  79. TERM_PUBLIC void COREL_options()
  80. {
  81.         struct value a;
  82.  
  83.                 if (!END_OF_COMMAND && almost_equals(c_token,"def$ault")) {
  84.                         corel_color=FALSE;
  85.                         strcpy(corel_font,"SwitzerlandLight");
  86.                         corel_fontsize = 22;
  87.                         corel_lw=CORELD_LW;
  88.                 corel_xmax=CORELD_XMAX;
  89.                 corel_ymax=CORELD_YMAX;
  90.             c_token++;
  91.                 }
  92.                 if (!END_OF_COMMAND && almost_equals(c_token,"mono$chrome")) {
  93.                         corel_color=FALSE;
  94.             c_token++;
  95.                 } else
  96.                 if (!END_OF_COMMAND && almost_equals(c_token,"color$")) {
  97.                         corel_color=TRUE;
  98.             c_token++;
  99.                 }
  100.                 if (!END_OF_COMMAND && isstring(c_token)) {
  101.                   quote_str(corel_font,c_token, MAX_ID_LEN);
  102.                   c_token++;
  103.                 }
  104.                 if (!END_OF_COMMAND) {
  105.                   /* We have font size specified */
  106.                   corel_fontsize = (int)real(const_express(&a));
  107.                   c_token++;
  108.                   term->v_char = (unsigned int)(corel_fontsize*COREL_SC);
  109.                   term->h_char = (unsigned int)(corel_fontsize*COREL_SC*6/10);
  110.                 }
  111.                 if (!END_OF_COMMAND) {
  112.                   corel_xmax=(unsigned int)(real(const_express(&a))*720);
  113.                   c_token++;
  114.                   if (!END_OF_COMMAND) {
  115.                     corel_ymax=(unsigned int)(real(const_express(&a))*720);
  116.                     c_token++;
  117.                   }
  118.                   term->xmax=corel_xmax;
  119.                   term->ymax=corel_ymax;
  120.                   term->v_tic=corel_ymax/80;
  121.                   term->h_tic=corel_ymax/80;
  122.                 }
  123.                 if (!END_OF_COMMAND) {
  124.                   corel_lw= real(const_express(&a))*COREL_SC;
  125.                   c_token++;
  126.                 }
  127.  
  128.         sprintf(term_options,"%s \"%s\" %d,%0.1f,%0.1f,%0.1f",
  129.                 corel_color ? "color" : "monochrome",corel_font,
  130.                 corel_fontsize,corel_xmax/720.0,corel_ymax/720.0,
  131.                 corel_lw/COREL_SC);
  132. }
  133.  
  134. TERM_PUBLIC void COREL_init()
  135. {
  136.     fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-1.2\n");
  137.         fprintf(outfile,"%%%%BoundingBox: %d %d %d %d\n", CORELD_XOFF,CORELD_YOFF,
  138.                 (int)((corel_xmax)/COREL_SC+0.5+CORELD_XOFF),
  139.                 (int)((corel_ymax)/COREL_SC+0.5+CORELD_YOFF) );
  140.         fprintf(outfile,"%%%%TemplateBox: %d %d %d %d\n", CORELD_XOFF,CORELD_YOFF,
  141.                 (int)((corel_xmax)/COREL_SC+0.5+CORELD_XOFF),
  142.                 (int)((corel_ymax)/COREL_SC+0.5+CORELD_YOFF) );
  143.     fprintf(outfile,"%%%%EndComments\n");
  144.     fprintf(outfile,"%%%%EndProlog\n");
  145.         fprintf(outfile,"%%%%BeginSetup\n%%%%EndSetup\n");
  146. }
  147.  
  148.  
  149. TERM_PUBLIC void COREL_graphics()
  150. {
  151.         corel_path_count = 0;
  152.         corel_stroke = FALSE;
  153. }
  154.  
  155.  
  156. TERM_PUBLIC void COREL_text()
  157. {
  158.         if (corel_stroke) {
  159.         fprintf(outfile,"S\n");
  160.                 corel_stroke = FALSE;
  161.     }
  162.         corel_path_count = 0;
  163. }
  164.  
  165.  
  166. TERM_PUBLIC void COREL_reset()
  167. {
  168.     fprintf(outfile,"%%%%Trailer\n");
  169. }
  170.  
  171.  
  172. TERM_PUBLIC void COREL_linetype(linetype)
  173. int linetype;
  174. {
  175.         if (corel_stroke) {
  176.         fprintf(outfile,"S\n");
  177.                 corel_stroke = FALSE;
  178.     }
  179.     switch(linetype) {
  180.                 case -2 : fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  181.                                 if (corel_color) {
  182.                     fprintf(outfile,"0 0 0 1 K\n");
  183.                 }
  184.                 else {                
  185.                                         fprintf(outfile,"[] 0 d\n");
  186.                                         fprintf(outfile,"0 j\n0 G\n");
  187.                 }
  188.                 break;
  189.  
  190.                 case -1 : fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  191.                                 if (corel_color) {
  192.                     fprintf(outfile,"0 0 0 1 K\n");
  193.                 }
  194.                 else {                
  195.                     fprintf(outfile,"[1 2] 0 d\n");
  196.                                         fprintf(outfile,"0 j\n0 G\n");
  197.                                 }
  198.                 break;
  199.                 
  200.                 case 0 :  fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  201.                                 if (corel_color) {
  202.                     fprintf(outfile,"1 0 1 0 K\n");
  203.                 }
  204.                 else {                
  205.                     fprintf(outfile,"[] 0 d\n");
  206.                                         fprintf(outfile,"2 j\n0 G\n");
  207.                                 }
  208.                 break;
  209.                 
  210.                 case 1 :  fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  211.                                 if (corel_color) {
  212.                     fprintf(outfile,"1 1 0 0 K\n");
  213.                 }
  214.                 else {                
  215.                     fprintf(outfile,"[4 2] 0 d\n");
  216.                                         fprintf(outfile,"2 j\n0 G\n");
  217.                                 }
  218.                 break;
  219.                 
  220.                 case 2 :  fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  221.                                 if (corel_color) {
  222.                     fprintf(outfile,"0 1 1 0 K\n");
  223.                 }
  224.                 else {                
  225.                                         fprintf(outfile,"[2 3] 0 d\n");
  226.                                         fprintf(outfile,"2 j\n0 G\n");
  227.                                 }
  228.                 break;
  229.                 
  230.                 case 3 :  fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  231.                                 if (corel_color) {
  232.                     fprintf(outfile,"0 1 0 0 K\n");
  233.                 }
  234.                 else {                
  235.                     fprintf(outfile,"[1 1.5] 0 d\n");
  236.                                         fprintf(outfile,"2 j\n0 G\n");
  237.                                 }
  238.                 break;
  239.                 
  240.                 case 4 :  fprintf(outfile,"%f w\n",corel_lw/COREL_SC);
  241.                                 if (corel_color) {
  242.                     fprintf(outfile,"1 0 0 0 K\n");
  243.                                 }
  244.                 else {                
  245.                     fprintf(outfile,"[5 2 1 2] 0 d\n");
  246.                                         fprintf(outfile,"2 j\n0 G\n");
  247.                                 }
  248.                 break;
  249.                 
  250.                 case 5 : fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  251.                                 if (corel_color) {
  252.                     fprintf(outfile,"0 0 1 0 K\n");
  253.                 }
  254.                 else {                
  255.                     fprintf(outfile,"[4 3 1 3] 0 d\n");
  256.                                         fprintf(outfile,"2 j\n0 G\n");
  257.                                 }
  258.                 break;
  259.                 
  260.                 case 6 : fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  261.                                 if (corel_color) {
  262.                     fprintf(outfile,"0 0 0 1 K\n");
  263.                 }
  264.                 else {                
  265.                     fprintf(outfile,"[2 2 2 4] 0 d\n");
  266.                                         fprintf(outfile,"2 j\n0 G\n");
  267.                                 }
  268.                 break;
  269.                 
  270.                 case 7 : fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  271.                                 if (corel_color) {
  272.                     fprintf(outfile,"0 0.7 1 0 K\n");
  273.                 }
  274.                 else {                
  275.                     fprintf(outfile,"[2 2 2 2 2 4] 0 d\n");
  276.                                         fprintf(outfile,"2 j\n0 G\n");
  277.                                 }
  278.                 break;
  279.                 
  280.                 case 8 : fprintf(outfile,"%.2f w\n",corel_lw/COREL_SC);
  281.                                 if (corel_color) {
  282.                     fprintf(outfile,"0.5 0.5 0.5 0 K\n");
  283.                 }
  284.                 else {                
  285.                     fprintf(outfile,"[2 2 2 2 2 2 2 4] 0 d\n");
  286.                                         fprintf(outfile,"2 j\n0 G\n");
  287.                                 }
  288.                 break;
  289.         }
  290.         corel_path_count = 0;
  291. }
  292.  
  293.  
  294. TERM_PUBLIC void COREL_move(x,y)
  295. unsigned int x,y;
  296. {
  297.         if (corel_stroke) fprintf(outfile,"S\n");
  298.         fprintf(outfile,"%0.2f %0.2f m\n", x/COREL_SC, y/COREL_SC);
  299.         corel_path_count += 1;
  300.         corel_stroke = TRUE;
  301. }
  302.  
  303.  
  304. TERM_PUBLIC void COREL_vector(x,y)
  305. unsigned int x,y;
  306. {
  307.         fprintf(outfile,"%.2f %.2f l\n", x/COREL_SC, y/COREL_SC);
  308.         corel_path_count += 1;
  309.         corel_stroke = TRUE;
  310.         if (corel_path_count >= 400) {
  311.                 fprintf(outfile,"S\n%.2f %.2f m\n",x/COREL_SC,y/COREL_SC);
  312.                 corel_path_count = 0;
  313.     }
  314. }
  315.  
  316.  
  317. TERM_PUBLIC void COREL_put_text(x,y,str)
  318. unsigned int x, y;
  319. char *str;
  320. {
  321. char ch;
  322.         if (corel_stroke) {
  323.         fprintf(outfile,"S\n");
  324.                 corel_stroke = FALSE;
  325.     }
  326.         switch(corel_justify) {
  327.                 case LEFT :   fprintf(outfile,"/_%s %d %d 0 0 z\n",
  328.                                       corel_font,corel_fontsize,corel_fontsize);
  329.             break;
  330.                 case CENTRE : fprintf(outfile,"/_%s %d %d 0 1 z\n",
  331.                                       corel_font,corel_fontsize,corel_fontsize);
  332.             break;
  333.                 case RIGHT :  fprintf(outfile,"/_%s %d %d 0 2 z\n",
  334.                                       corel_font,corel_fontsize,corel_fontsize);
  335.             break;
  336.     }
  337.         if (corel_ang==0) {
  338.                 fprintf(outfile,"[1 0 0 1 %.2f %.2f]e\n0 g\n",
  339.                         x/COREL_SC,y/COREL_SC - corel_fontsize/3.0);
  340.     }
  341.     else {
  342.                 fprintf(outfile,"[0 1 -1 0 %.2f %.2f]e\n0 g\n",
  343.                         x/COREL_SC - corel_fontsize/3.0,y/COREL_SC);
  344.     }
  345.         
  346.     putc('(',outfile);
  347.     ch = *str++;
  348.     while(ch!='\0') {
  349.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  350.             putc('\\',outfile);
  351.         putc(ch,outfile);
  352.         ch = *str++;
  353.     }
  354.         fprintf(outfile,")t\nT\n");
  355.         corel_path_count = 0;
  356. }
  357.  
  358. TERM_PUBLIC int COREL_text_angle(ang)
  359. int ang;
  360. {
  361.         corel_ang=ang;
  362.     return TRUE;
  363. }
  364.  
  365. TERM_PUBLIC int COREL_justify_text(mode)
  366. enum JUSTIFY mode;
  367. {
  368.         corel_justify=mode;
  369.     return TRUE;
  370. }
  371.  
  372. #endif /* TERM_BODY */
  373.  
  374. #ifdef TERM_TABLE
  375.  
  376. TERM_TABLE_START(corel_driver)
  377.     "corel","EPS format for CorelDRAW",
  378.      CORELD_XMAX, CORELD_YMAX, CORELD_VCHAR, CORELD_HCHAR,
  379.      CORELD_VTIC, CORELD_HTIC, COREL_options, COREL_init, COREL_reset,
  380.      COREL_text, null_scale, COREL_graphics, COREL_move, COREL_vector,
  381.      COREL_linetype, COREL_put_text, COREL_text_angle,
  382.      COREL_justify_text, do_point, do_arrow, set_font_null
  383. TERM_TABLE_END(corel_driver)
  384.  
  385. #undef LAST_TERM
  386. #define LAST_TERM corel_driver
  387.  
  388. #endif /* TERM_TABLE */
  389. #endif /* TERM_PROTO_ONLY */
  390.  
  391. /*
  392.  * NAME: corel 
  393.  *
  394.  * OPTIONS: mode "fontname" fontsize,xsize,ysize,linewidth
  395.  *        mode= color or monochrome             (default=mono)
  396.  *        "fontname"= postscript font name      (default="SwitzerlandLight")
  397.  *        fontsize  = size of font in points    (default=22pt)
  398.  *        xsize     = width of page in inches   (default=8.2in)
  399.  *        ysize     = height of page in inches  (default=10in)
  400.  *        linewidth = width of lines in points  (default=1.2pt)
  401.  *
  402.  * SUPPORTS: CorelDraw EPS format
  403.  *
  404.  * Further Info: Import from CorelDraw with the CorelTrace filter.
  405.  *
  406.  */